using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using SCS.Common.Models;
namespace SCS.DAL.Mapping
{
    public class TeachingAssignmentMap : EntityTypeConfiguration<TeachingAssignment>
    {
        public TeachingAssignmentMap()
        {
            // Primary Key
            this.HasKey(t => t.teachingAssignmentID);

            // Properties
            this.Property(t => t.teachingAssignmentID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            // Table & Column Mappings
            this.ToTable("TeachingAssignment");
            this.Property(t => t.teachingAssignmentID).HasColumnName("teachingAssignmentID");
            this.Property(t => t.teacherID).HasColumnName("teacherID");
            this.Property(t => t.classID).HasColumnName("classID");
            this.Property(t => t.subjectID).HasColumnName("subjectID");
            this.Property(t => t.schoolYearID).HasColumnName("schoolYearID");

            // Relationships
            this.HasRequired(t => t.Class)
                .WithMany(t => t.TeachingAssignments)
                .HasForeignKey(d => d.classID);
            this.HasRequired(t => t.SchoolYear)
                .WithMany(t => t.TeachingAssignments)
                .HasForeignKey(d => d.schoolYearID);
            this.HasOptional(t => t.Subject)
                .WithMany(t => t.TeachingAssignments)
                .HasForeignKey(d => d.subjectID);
            this.HasRequired(t => t.Teacher)
                .WithMany(t => t.TeachingAssignments)
                .HasForeignKey(d => d.teacherID);

        }
    }
}
